~ chicken-core (chicken-5) /manual/Module (chicken format)
Trap1[[tags: manual]]
2[[toc:]]
3
4== Module (chicken format)
5
6This module provides procedures for formatting output to ports and
7strings.
8
9=== The printf family of procedures
10
11==== printf
12==== fprintf
13==== sprintf
14
15<procedure>(fprintf PORT FORMATSTRING [ARG...])</procedure><br>
16<procedure>(printf FORMATSTRING [ARG...])</procedure><br>
17<procedure>(sprintf FORMATSTRING [ARG...])</procedure>
18
19Simple formatted output to a given port ({{fprintf}}), the
20value of {{(current-output-port)}} ({{printf}}), or a string
21({{sprintf}}). The {{FORMATSTRING}} can contain any sequence
22of characters. There must be at least as many {{ARG}} arguments given as there are format directives that require an argument in {{FORMATSTRING}}. Extra {{ARG}} arguments are ignored. The character `~' prefixes special formatting directives:
23
24<table>
25<tr><td>~%</td><td>
26write newline character
27</td></tr><tr><td> ~N</td><td>
28the same as {{~%}}
29</td></tr><tr><td> ~S</td><td>
30write the next argument
31</td></tr><tr><td> ~A</td><td>
32display the next argument
33</td></tr><tr><td> ~\n</td><td>
34skip all whitespace in the format-string until the next non-whitespace character
35</td></tr><tr><td> ~B</td><td>
36write the next argument as a binary number
37</td></tr><tr><td> ~O</td><td>
38write the next argument as an octal number
39</td></tr><tr><td> ~X</td><td>
40write the next argument as a hexadecimal number
41</td></tr><tr><td> ~C</td><td>
42write the next argument as a character
43</td></tr><tr><td> ~~</td><td>
44display `~'
45</td></tr><tr><td> ~!</td><td>
46flush all pending output
47</td></tr><tr><td> ~?</td><td>
48invoke formatted output routine recursively with the next two arguments as format-string and list of parameters
49</td></tr></table>
50
51
52=== format
53
54<procedure>(format [DESTINATION] FORMATSTRING [ARG...])</procedure>
55
56The parameters {{FORMATSTRING}} and {{ARG...}} are as for {{printf}}.
57
58The optional {{DESTINATION}}, when supplied, performs:
59
60; {{#f}} : {{sprintf}}
61; {{#t}} : {{printf}}
62; {{output-port}} : {{fprintf}}
63; : {{sprintf}}
64
65
66---
67Previous: [[Module (chicken foreign)]]
68
69Next: [[Module (chicken gc)]]